﻿
$(document).ready(function () {
    
    $("a.iframe").colorbox({ opacity: 0, iframe: true, innerWidth: 742, innerHeight: 569, fixed: true });
    $(".fancyboxV").colorbox({ opacity: 0, iframe: true, innerWidth: 604, innerHeight: 330, fixed: true });
    $(".fancyboxC").colorbox({ opacity: 0, iframe: true, innerWidth: 603, innerHeight: 265, fixed: true });
    $(".fancyboxN").colorbox({ opacity: 0, iframe: true, innerWidth: 603, innerHeight: 260, fixed: true });
    $(".fancyboxT").colorbox({ opacity: 0, iframe: true, innerWidth: 600, innerHeight: 540, fixed: true });
    //$(".fancyboxS").colorbox({ opacity: 0, iframe: true, innerWidth: 768, innerHeight: 500, fixed: true });

    $(".scrollLoading").scrollLoading();

    $('[data-toggle="tooltip"]').tooltip();

    var owl = $('.owl-carousel');
    owl.owlCarousel({
        loop: true,
        margin: 15,
        //nav: true,
        autoplay:true,
        autoplayTimeout:3000,
        autoplayHoverPause:false,
        responsive: {
            0: {
                items: 1
            },
            600: {
                items: 2
            },
            960: {
                items: 3
            },
            1200: {
                items: 4
            }
        }
    });

    $(document).on("click",".btn-dec", function () {
        var result = $(this).parent(".add-qty").find(".qty");
        var qty = result.val();
        if (!isNaN(qty) && qty > 1) {
            qty--;
            result.val(qty);
        }
    });

    $(document).on("click",".btn-inc", function () {
        var result = $(this).parent(".add-qty").find(".qty");
        var qty = result.val();
        if (!isNaN(qty) && qty < 99) {
            qty++;
            result.val(qty);
        }
    });

    $(document).on("input propertychange",".qty", function () {
        if (this.value.length == 1) {
            this.value = this.value.replace(/[^1-9]/g, '')
        }
        else {
            this.value = this.value.replace(/\D/g, '')
        }
    });

    
});


/*Tabs*/
function ptabs(tab) {
    
    $("#ptablist > li").removeClass("active");
    $("#li_" + tab).addClass('active');

    if (tab == 'overview') {
        $("#overview").css("display", "");
        $("#compatibility").css("display", "");
        $("#images").css("display", "");
        $("#shipping").css("display", "");
        $("#warranty").css("display", "");
    }
    if (tab == 'images') {
        $("#overview").css("display", "none");
        $("#images").css("display", "");
        $("#compatibility").css("display", "");
        $("#shipping").css("display", "");
        $("#warranty").css("display", "");
    }
    if (tab == 'compatibility') {
        $("#overview").css("display", "none");
        $("#images").css("display", "none");
        $("#compatibility").css("display", "");
        $("#shipping").css("display", "");
        $("#warranty").css("display", "");
    }
    if (tab == 'shipping') {
        $("#overview").css("display", "none");
        $("#compatibility").css("display", "none");
        $("#images").css("display", "none");
        $("#shipping").css("display", "");
        $("#warranty").css("display", "");
    }
    if (tab == 'warranty') {
        $("#overview").css("display", "none");
        $("#compatibility").css("display", "none");
        $("#images").css("display", "none");
        $("#shipping").css("display", "none");
        $("#warranty").css("display", "");
    }
}


/*get shopping cart button*/
function getcartform(brandnav, productmodel, productID, modelName, cartID, smallPic, ProductUrl, stockID) {
    var carttext = "";
    var picture = "";

    productmodel = productmodel.replace("'", "");

    var Url = "../Common/Cart.ashx?modelName=" + modelName + "&pid=" + productID + "&pmodel=" + productmodel + "&spic=" + smallPic + "&purl=" + ProductUrl + "&brandnav=" + brandnav;

    $.ajax({
        type: "POST",
        url: Url,
        cache: false,
        success: function (json) {
            json2 = eval(json);
            $.each(json2, function (i) {

                instock = json2[i].instock;
                picture = json2[i].picture;
                carttext = unescape(json2[i].carttext);

                $("#" + stockID).html(instock);
                $("#" + cartID).html(carttext);

            });
        }
    });
}

